package com.mc.lp.security.user;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import com.mc.lp.view.constants.IConstants;

public class SimpleAuthenticationFailureHandler extends AbstractAuthenticationHandler implements AuthenticationFailureHandler, IConstants {
	protected Logger logger = Logger.getLogger(SimpleAuthenticationSuccessHandler.class);
	public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
		clearAuthenticationAttributes(request);
		handle(request, response, exception);
	}

	protected void handle(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
		if (response.isCommitted()) {
			logger.info("Response already committed : SimpleAuthenticationFailureHandler");
			return;
		}
		redirectStrategy.sendRedirectOnFailure(request, response, exception);
	}

}